﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AddCustomerRelation.aspx.cs" Inherits="ZX.WebApp.Crm.Customer.AddCustomerRelation" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/connection/connection-min.js"></script>
    <script src="../../Scripts/jquery-1.6.min.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery.json-2.2.min.js" type="text/javascript"></script>
    <script src="../../Scripts/Jquery.form.js" type="text/javascript"></script>
    <script src="../../Scripts/CombinButton.js" type="text/javascript"></script>
    <link href="../../Styles/base.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table id="fieldTable">
            <tr>
                <td>公司名称：<span style="color: Red">*</span></td>
                <td>
                    <input type="hidden" id="RelationCustomerName" runat="server" />
                    <input type="text" id="txtRelationCustomerName" runat="server" title="如果系统中存在则选择,否则输入公司名称"
                        style="width:150px;" />
                    <button id="btnRelationCustomerName" name="0" type="button" class="btnCheck">
                            选择</button>
                </td>
            </tr>
            <tr>
                <td>所属关系：<span style="color: Red">*</span></td>
                <td>
                    <asp:DropDownList ID="CustomerRelation" runat="server" Width="160px" AppendDataBoundItems="true">
                        <asp:ListItem Value=""> </asp:ListItem>
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td>备注：</td>
                <td>
                    <asp:TextBox ID="Explain" runat="server" MaxLength="100" 
                        TextMode="MultiLine" Width="150" Height="100"></asp:TextBox>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
<script type="text/javascript">
    var CustomerID = "<%=CustomerId %>", RelationID = "<%=RelationId %>";
    var instance = [{ "CustomerID": "", "RelationCustomerID": "", "RelationCustomerName": "",
        "CustomerRelation": "", "Explain": ""
    }];
    function Save() {
        var RelationCustomerID = $("#RelationCustomerName").val();
        var RelationCustomerName = $("#txtRelationCustomerName").val();
        var CustomerRelation = $("#CustomerRelation").val();
        var Explain = $("#Explain").val().replace(/(^\s*)|(\s*$)/g, '');
        if (RelationCustomerID == "") {
            RelationCustomerID = "00000000-0000-0000-0000-000000000000";
            parent._DialogState = "0";
        }
        if (RelationCustomerName == "") {
            alert("客户名称不能为空!");
            $("#txtRelationCustomerName").focus();
            parent._DialogState = "0";
            return;
        }
        if (CustomerRelation == "") {
            alert("所属关系不能为空!");
            $("#CustomerRelation").focus();
            parent._DialogState = "0";
            return;
        }
        instance[0].CustomerID = CustomerID;
        instance[0].RelationCustomerID = RelationCustomerID;
        instance[0].RelationCustomerName = RelationCustomerName;
        instance[0].CustomerRelation = CustomerRelation;
        instance[0].Explain = Explain;
        var json = $.toJSON(instance[0]).replace(/'/g, "[B]");
        SaveData(json);
        parent._DialogState = "";
    }
    function SaveData(obj) {
        YAHOO.util.Connect.asyncRequest('POST', '../../Extend/AjaxData/CustomOperating.aspx?rid=' + RelationID + '&action=insert&entity=CrmCustomerRelation&json=' + encodeURI(obj) + '', {
            success: function (res) {
                var inventory;
                try {
                    inventory = res.responseText;
                    if (inventory == "1") {
                        alert("保存成功!");
                        location.reload(false);
                        parent.LoadCustomerRelation();
                    } else {
                        alert("保存失败!");
                    }
                }
                catch (e) {
                }
                finally {
                }
            },
            failure: function (error) {
                alert("数据错误：" + error.statusText);
            }
        }, null);
    }
</script>
</html>
